#*******************************************************************
#* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        *
#*                                                                 *
#*  NOTE      = http协议分析
#*  DATE      =
#*******************************************************************

#  把frmain.c 中  main函数注释掉

NULLSTRING              :=
SPACE                   := $(NULLSTRING) # end of the line
PROTOCOL_ANALYZER_DIR   := $(shell T_DIRNAME=`dirname $(CURDIR)`;T_BASENAME=`basename $(CURDIR)`;until [[ $$T_DIRNAME = "/" || $$T_BASENAME = "protocol_analyzer" ]];do T_DIRNAME=`dirname $$T_DIRNAME`;T_BASENAME=`basename $$T_DIRNAME`;done;echo $$T_DIRNAME)
MODULE                  := $(firstword $(subst /,$(SPACE),$(subst $(PROTOCOL_ANALYZER_DIR)/test/,,$(CURDIR))))
include                 $(PROTOCOL_ANALYZER_DIR)/test/comm/Makefile_comm.mk
include                 $(PROTOCOL_ANALYZER_DIR)/dist/dev/include/apmmodule/Makefile_comm.mk

LIB_A_APM_COMM          := $(PROTOCOL_ANALYZER_DIR)/src/lib/apmcomm/apm_comm_1.0.a

INCLUDES                = -I. -I$(LIB_I_APM_COMM) -I$(LIB_I_APM_MODULE) -I$(LIB_I_TEST_COMM) -I$(PROTOCOL_ANALYZER_DIR)/src/exec/framework -I$(PROTOCOL_ANALYZER_DIR)/../common/protoc/src/c -I$(PROTOCOL_ANALYZER_DIR)/../common/protoc/src/client
LIBS                    = -lzlog -lpthread -luuid -lcunit -ljson-c `xml2-config --libs`
CFLAGS                  = -fPIC `xml2-config --cflags`

ifeq ($(enable_dbg_rdel), 0)
    LIBS += -lluajit-5.1
endif
ifeq ($(enable_dbg_rdel), 5)
    LIBS += -lluajit-5.1
endif

CFLAGS                  += $(CFLAGS_EXT)
LIBS                    += $(LIBS_EXT)

TEST_TARGETS            = test_$(MODULE)

MODULE_VERSION          := $(COMM_FRAMEWORK_VER).$(L7_VERSION)

TEST_SOURCE_FILES       := $(shell find . -name "*.c" -o -name "*.h" | sed 's|./||')

.PHONY:clean
all: $(LIB_A_APM_COMM) $(TEST_TARGETS) run

$(LIB_A_APM_FRAME): $(LIB_A_APM_FRAME_OBJS)
	echo $^ | xargs ar crv $(LIB_A_APM_FRAME) && ranlib $(LIB_A_APM_FRAME)

$(LIB_A_APM_COMM):
	$(MAKE) CFLAGS_UTEST=-DAPMTEST_CUNIT -C $(APM_COMM_SRC_DIR) all

$(TEST_TARGETS): $(TEST_SOURCE_FILES) $(COMM_TEST_CFILES) $(LIB_A_APM_FRAME)
	$(CX) $(CFLAGS) $(COMM_TEST_CFILES) $(filter %.c,$(TEST_SOURCE_FILES)) $(LIB_A_APM_FRAME) $(LIB_A_APM_MODULE) $(LIB_A_APM_COMM) -o $@ $(INCLUDES) $(LIBS)

run:
	$(VG) ./$(TEST_TARGETS)

clean:
	find . -name "*.o" | xargs rm -f
	rm -f $(TEST_TARGETS)

#EOF
